#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, k, d[1000003], nd[12], ans = 1ll << 60;
vector<int> edges[1000003];

void dfs(int i, int sum) {
	if (sum >= ans) return;
	if (i == n + 1) {
		for (int j = 1; j <= n; ++j) {
			int tmp = j, yk = k;
			while (yk--) tmp = nd[tmp];
			if (tmp != 1) return;
		}
		ans = min(ans, sum);
		return;
	}
	for (int j = 1; j <= n; ++j) {
		nd[i] = j;
		dfs(i + 1, sum + (j != d[i]));
	}
}

int dfs2(int i, int dp) {
	int ansr = dp;
	for (auto j : edges[i]) {
		ansr = max(ansr, dfs2(j, dp + 1));
	}
	if (ansr - dp == k - 1) {
		if (d[i] != 1) {
			d[i] = 1;
			++ans;
			return dp - 1;
		}
	}
	return ansr;
}

signed main() {
	freopen("lost.in", "r", stdin);
	freopen("lost.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> d[i];
	}
	if (k == 1 && 0) {
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
			ans += (d[i] != 1);
		}
		cout << ans << "\n";
	} else if (n <= 8 && 0) {
		dfs(1, 0);
		cout << ans << "\n";
	} else {
		ans = 0;
		for (int i = 1; i <= n; ++i) {
			if (i == 1) {
				if (d[i] == 1);
				else {
					++ans;
					d[i] = 1;
				}
			} else edges[d[i]].push_back(i);
		}
		dfs2(1, 1);
		cout << ans << "\n";

	}
	return 0;
}
/*
 */

